package com.example.demo.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.entities.Order;
import com.example.demo.service.OrderService;

@RestController
@RequestMapping("test")
public class OrderController {
	@Autowired
	private OrderService orderServiceImp ;
	
	@PutMapping("updateBatch")
	public void updateBatch(@RequestBody List<Order> orders,HttpServletResponse res ,HttpServletRequest req) throws IOException {
		this.orderServiceImp.updateBatch(orders);
		System.out.println("------->进入了controller");
		res.sendRedirect(req.getContextPath()+"/test/successful");
	
	}
	//重定向
	@GetMapping("successful")
	public String successful() {
		return "200";		
	}
	/** 可以直接用Map将对相应的实体信息返回，不用经过实体的方式是最快捷的方式 */
	@GetMapping("selectAllOrder")
	public List<Order> selectAll(){
		return orderServiceImp.selectAll();
	}
	@GetMapping("emport")
	public String emport() {
		return "" + null;
	}
}
